home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / windows / ini_lib3.zip / TEST.C < prev    next >
C/C++ Source or Header  |  1997-05-09  |  3KB  |  120 lines

  1. /*  INI File Test Program
  2.  
  3.     This program test the "ini" file library.
  4.     Author:     Sam Saprunoff
  5.     Date:       01/23/95
  6.  
  7.     The user is free to use the libraries and this demo as he/she sees fit.
  8.  
  9. */
  10.  
  11. #include<stdio.h>
  12.  
  13. #include"ini.h"                         // Include return values
  14.  
  15.  
  16. main()
  17. {
  18.  
  19.  // The ini lib will return a character string from the ini file.  So ensure
  20.  //  the the passed string is large enough to accomodate your parameter.
  21.  
  22.  char ret_string[100];
  23.  int add = 0;
  24.  
  25.  
  26.  printf("\n\nINI File Parse Test");
  27.  printf("\nFilename: Test.ini");
  28.  
  29.  // The format to call the function is:
  30.  //     read_ini( "filename", "square bracket name", "value name", char buffer);
  31.  //     i.e. file will have:
  32.  //          [header]
  33.  //          value=12
  34.  //
  35.  
  36.  
  37.  // The first sample is to use a switch statement //
  38.  // Here the returned data is in the character buffer //
  39.  
  40.  printf("\n\nTest1: Find [header] a =");
  41.  
  42.  switch( read_ini("test.ini", "header1","a", ret_string ) )
  43.    {
  44.       case INI_FOUND:
  45.     printf("\nFound Data: %s", ret_string);
  46.     break;
  47.  
  48.       case INI_NOT_FOUND:
  49.     printf("\nData NOT Found");
  50.     break;
  51.  
  52.       case INI_FILE_ERROR:
  53.     printf("\nINI File Error");
  54.     break;
  55.    }
  56.  
  57.  // The second sample is done via an if statement.  Here we actually want the
  58.  //  returned data to be a numeric value.  To do this use sscanf and read
  59.  //  the data from the character buffer into a numeric variable
  60.  
  61.  
  62.  printf("\n\n\nTest2: Find [header2] address=");
  63.  
  64.  if ( read_ini("test.ini", "header2","address", ret_string ) == INI_FOUND )
  65.    {
  66.     sscanf( ret_string, "%x", &add);
  67.     printf("\nAddress = %x", add);
  68.    }
  69.  else
  70.    printf("\naddress not found");
  71.  
  72.  
  73.  // The third sample demonstrates that if the first column contains a ";" then
  74.  // the line is ignored
  75.  
  76.  printf("\n\n\nTest3: Find [header3] d =");
  77.  
  78.  if ( read_ini("test.ini", "header3","d", ret_string ) == INI_FOUND )
  79.    {
  80.     sscanf( ret_string, "%u", &add);
  81.     printf("\nd = %u", add);
  82.    }
  83.  else
  84.    printf("\nd not found");
  85.  
  86.  
  87.  // The fourth sample demonstrates that if the "value name" is under a
  88.  //  different "bracketed name" the system will not find it
  89.  
  90.  printf("\n\n\nTest4: Find [header2] c =");
  91.  
  92.  if ( read_ini("test.ini", "header2","c", ret_string ) == INI_FOUND )
  93.    {
  94.     printf("\nc = %s", ret_string);
  95.    }
  96.  else
  97.    printf("\nc not found");
  98.  
  99.  
  100.  
  101.  // The fifth sample demonstrates the updating of data
  102.  
  103.  printf("\n\n\nTest5: Update [header1] a = 9");
  104.  
  105.  if ( write_ini("test.ini", "header1","a", "9" ) == INI_UPDATE_SUCCESS )
  106.    {
  107.     printf("\nUpdate Successful");
  108.    }
  109.  else
  110.    printf("\nUpdate Not Successful");
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  printf("\n\n");
  118.  
  119. } // End of Main
  120.